﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.IO;

namespace PB.LOG.WP7.Helpers
{
    public static class IsolatedStorageHelper
    {
        public static object FileOperation(string fileName, FileMode fileMode, FileAccess fileAccess, Func<Stream, object> fileOperation)
        {
            using (IsolatedStorageFile userStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(fileName, fileMode, fileAccess, userStore))
                {
                    return fileOperation(stream);
                }
            }
        }

        public static void FileOperation(string fileName, FileMode fileMode, FileAccess fileAccess, Action<Stream> fileOperation)
        {
            FileOperation(fileName, fileMode, fileAccess, stream =>
            {
                fileOperation(stream);
                return null;
            });
        }
    }
}
